Fix relative `build.target-dir` configuration
authorAlex Crichton <alex@alexcrichton.com>
Mon, 16 May 2016 18:09:52 +0000 (11:09 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 16 May 2016 18:09:52 +0000 (11:09 -0700)
Closes #2700

src/cargo/util/config.rs
tests/test_cargo_compile_custom_build.rs

index cc048ea36590a718c530301c315b0a31779e8c46..b03b68379027657cd04133d38766197814a9c573 100644 (file)
@@ -366,7 +366,8 @@ impl Config {
         if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
             *self.target_dir.borrow_mut() = Some(Filesystem::new(self.cwd.join(dir)));
         } else if let Some(val) = try!(self.get_path("build.target-dir")) {
-            *self.target_dir.borrow_mut() = Some(Filesystem::new(val.val));
+            let val = self.cwd.join(val.val);
+            *self.target_dir.borrow_mut() = Some(Filesystem::new(val));
         }
         Ok(())
     }
index dc5d384f9f2558d9256381ea7e7e6996e21ede00..6a4d3679ee7c732de013c063fa8357c5d9e9da0f 100644 (file)
@@ -1892,3 +1892,33 @@ test!(non_utf8_output {
     assert_that(p.cargo_process("build").arg("-v"),
                 execs().with_status(0));
 });
+
+test!(custom_target_dir {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            a = { path = "a" }
+        "#)
+        .file("src/lib.rs", "")
+        .file(".cargo/config", r#"
+            [build]
+            target-dir = 'test'
+        "#)
+        .file("a/Cargo.toml", r#"
+            [project]
+            name = "a"
+            version = "0.5.0"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("a/build.rs", "fn main() {}")
+        .file("a/src/lib.rs", "");
+
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(0));
+});